﻿/* TextHelper
 */

/*待测试*/
namespace LSLib.TextEx
{
    using System.Collections.Generic;
    using System.IO;
    using System.Text;

    public static class TextHelper
    {
        /// <summary>加载文件内容
        /// </summary>
        /// <param name="file">文件全路径</param>
        /// <param name="encoding">文本编码格式</param>
        /// <returns>返回文本内容</returns>
        public static string LoadFile(string file, Encoding encoding)
        {
            if (File.Exists(file) == false) throw new FileNotFoundException("File is not exists.", file);

            List<byte> list;
            using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                list = new List<byte>((int)fs.Length);
                int b = 0;
                while ((b = fs.ReadByte()) != -1)
                {
                    list.Add((byte)b);
                }
            }

            return encoding.GetString(list.ToArray());
        }

    }
}
